<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>DOM注册其他事件</title>
    <style>
      .box {
        width: 20vw;
        height: 20vw;
        background-color: red;
      }
    </style>
  </head>

  <body>
    <div class="box"></div>
    <input type="text" class="inp" placeholder="请输入" />

    <script>
      // 盒子例子
      const box = document.querySelector(".box");
      box.addEventListener("mouseenter", function () {
        console.log("鼠标进入盒子");
        this.style.backgroundColor = "green";
      });
      box.addEventListener("mouseleave", function () {
        console.log("鼠标离开盒子");
        this.style.backgroundColor = "red";
      });
      // 输入框例子
      const inp = document.querySelector(".inp");
      inp.addEventListener("focus", function () {
        this.style.width = "200px";
        this.style.height = "50px";
      });
      inp.addEventListener("keydown", function (e) {
        console.log("键盘按下和弹起事件：" + e.key);
      });
      inp.addEventListener("input", function () {
        console.log("监听输入框输入事件：" + this.value);
      });
    </script>
  </body>
</html>
